
/**
 * @name NetCDFInterrogator
 *
 * @version 0.1.504 Alpha, MASS Wind Gradient 1, 4th commit
 * @date 10/4/2013
 * @author Niko Simonson
 * @author Brett Yasutake
 */
import java.io.IOException;
import java.util.List;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
import ucar.ma2.*;

/**
 * @name NetCDFInterrogator Test driver for reading NetCDF files
 *
 */
public class NetCDFInterrogator {

    private static final String FILENAME = "WindGradientProvenance";

    public static void main(String args[]) {

        NetcdfFile targetFile = null;

        try {
            targetFile = NetcdfFile.open(FILENAME, null);               // Open the file
            List<Variable> targetVariables = targetFile.getVariables();	// Get list of file's variables

            System.out.println("Number of variables in file: " + targetVariables.size());
            System.out.println();

            System.out.println("getdetailinfo: " + targetFile.getDetailInfo());
            System.out.println("filetypedesc " + targetFile.getFileTypeDescription());

            // Read each variable
            for (int i = 0; i < targetVariables.size(); i++) {

                Variable curr = targetVariables.get(i); // Get the current Variable

                System.out.print("Index " + i + ": ");

                ArrayDouble.D2 d3values = (ArrayDouble.D2) curr.read();
                System.out.println("XXXXXXXX " + d3values.getSize() + "XXXXXXXXXXXXXXXX");


                Index indx = d3values.getIndex();

                double totalTemp = 0.0;

                IndexIterator iter = d3values.getIndexIterator();

                while (iter.hasNext()) {
                    iter.next();
                    System.out.print(iter.getCurrentCounter()[0]
                            + ", " + iter.getCurrentCounter()[1] + ", "
                            + ": " + iter.getDoubleCurrent() + " ");
                }
            }

            System.err.println(targetFile.getGlobalAttributes().toString());
            System.err.println(targetFile.getTitle());

        } catch (java.io.IOException e) {
            e.printStackTrace();
            return;
        } finally {		// Close out the file no matter what occurs
            if (targetFile != null) {
                try {
                    targetFile.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }
    }
}
